package com.itheima.controller;

import com.itheima.pojo.*;
import com.itheima.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class UserController {

    private final UserService userService;

    @PostMapping
    public PageResult page(@RequestBody PageQuery<User> pageQuery){
        PageResult pageResult= userService.page(pageQuery);
        return pageResult;

    }
    //登录
    @PostMapping("/login")
    public Result login(@RequestBody User user){
        UserLoginVo vo =userService.login(user);
        Result result= new Result();
        if(vo==null){
            result.setMsg("账号或密码错误");
            result.setCode(404);
            return result;

        }
        result.setData(vo);
        result.setCode(200);
        return result;

    }

}
